<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>创客手机网站</title>
  <script src="/wap/js/flexible.js"></script>
  <script src="/wap/js/jquery-3.2.1.min.js"></script>
  <script src="/wap/js/util.js"></script>
  <link rel="stylesheet" href="/wap/css/style.css">
  <style>
    html {
      background: #f3f5f7;
    }
  </style>
</head>
<body>
<div id="bankCard">
  <input type="hidden" name="_token" value="{{csrf_token()}}">
  <div class="card-list">
    @if(empty($data))
    <p style="font-size: 0.43rem;color: #666666;margin-top: 3rem;text-align: center;">您还没有添加银行卡</p>
    @else
      @foreach($data as $v)
    <div class="card-list-item">
      <div  class="card-list-item-info" onclick="location.href='/wap/index/withdraw/{{ $id }}/{{ $v['id'] }}'">
        <div>{{ $v['bank']['bank_name'] }}</div>
        <div>{{ substr_replace($v['account_code'],str_repeat('X',strlen($v['account_code'])-8),4,-4) }}</div>
      </div>
      <div class="card-list-item-btn">
        <div class="item-btn fr" data-id="{{ $v['id'] }}"  onclick="showPopup(this)">
          <span>删除</span>
        </div>
      </div>
    </div>
      @endforeach
    @endif
  </div>
  <div class="shadow" style="display: none">
    <div class="popup">
      <div class="title">删除</div>
      <div class="desc">确认要删除当前所选的银行卡吗？</div>
      <div class="btn-list">
        <div class="btn-item-bor"></div>
        <div class="btn-item" data-id="" onclick="showPopup(this)">
          取消
        </div>
        <div class="btn-item c-e60012" data-id="" id="confirm" onclick="success(this)">
          确定
        </div>
      </div>
    </div>
  </div>
  @if(empty($data))
  <div class="detail__btn" onclick="location.href='/wap/index/addBankAccount/{{ $id }}'">添加银行卡</div>
  @endif
</div>
</body>
</html>

<script>
    function success(obj){
        $('.shadow').toggle();
        var csrf_token = $('input[name="_token"]').val();
        var id = $(obj).data('id');
        $.ajax({
            type: 'post',
            url: '{{ route('wap.index.delBankAccount') }}',
            data: {'id':id,'_token':csrf_token},
            dataType: "JSON",
            async: false,
            success: function (res) {
                if(res.status=='FAIL'){
                    toast(res.message,2000);
                }else{
                    toast('操作成功',2000);
                    location.reload();
                }
            },
            error: function (res) {
                console.log(res, 'error');
            }
        });
    }
    function showPopup(obj){
        $('#confirm').attr('data-id',$(obj).data('id'));
        $('.shadow').toggle();
    }
</script>